package com.mazaiting.socket.runner;

import com.mazaiting.socket.util.NioServerUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import com.mazaiting.socket.properties.ServerProperties;

import javax.annotation.Resource;

/**
 * 服务启动配置
 *
 * @author mazaiting
 * @create_time 2022/4/18 13:31
 */
@Component
public class ServerRunner implements ApplicationRunner {
    /**
     * 日志工具
     */
    private final Logger logger = LoggerFactory.getLogger(getClass());
    /**
     * 服务配置文件
     */
    @Resource
    private ServerProperties serverProperties;

    @Override
    public void run(ApplicationArguments args) {
        serverProperties.getServerConfigs().forEach(config -> {
            try {
                NioServerUtil.start(config, request -> "djalkfjalksjfalsjflkqjoieruwoiqjrkqnlnjlkfjalkfjalksjdjalkfjalksjfalsjflkqjoieruwoiqjrkqnlnjlkfjalkfjalksjm" +
                        "djalkfjalksjfalsjflkqjoieruwoiqjrkqnlnjlkfjalkfjalksjdjalkfjalksjfalsjflkqjoieruwoiqjrkqnlnjlkfjalkfjalksj," +
                        "djalkfjalksjfalsjflkqjoieruwoiqjrkqnlnjlkfjalkfjalksjdjalkfjalksjfalsjflkqjoieruwoiqjrkqnlnjlkfjalkfjalksj" +
                        "djalkfjalksjfalsjflkqjoieruwoiqjrkqnlnjlkfjalkfjalksjdjalkfjalksjfalsjflkqjoieruwoiqjrkqnlnjlkfjalkfjalksjkl" +
                        "djalkfjalksjfalsjflkqjoieruwoiqjrkqnlnjlkfjalkfjalksjdjalkfjalksjfalsjflkqjoieruwoiqjrkqnlnjlkfjalkfjalksjdjalkfjalksjfalsjflkqjoieruwoiqjrkqnlnjlkfjalkfjalksj" +
                        "djalkfjalksjfalsjflkqjoieruwoiqjrkqnlnjlkfjalkfjalksjdjalkfjalksjfalsjflkqjoieruwoiqjrkqnlnjlkfjalkfjalksj" +
                        "djalkfjalksjfalsjflkqjoieruwoiqjrkqnlnjlkfjalkfjalksjdjalkfjalksjfalsjflkqjoieruwoiqjrkqnlnjlkfjalkfjalksj");

            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }
}
